<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <p>你还可以输入 <em id="section">0</em>/150</p>
    <textarea name="" id="txt" cols="30" rows="10"></textarea>
    <button id="txt_btn">提交</button>
    <script>
        var em=document.getElementById("section");
        var txt=document.getElementById("txt")
        var p=document.getElementsByTagName('p')[0];
        var txt_btn=document.getElementById('txt_btn');
        txt.onkeyup=function(){
            var length=this.value.length;
            em.innerHTML=length;
            if(length>=10) {p.innerHTML="不能输入了"; txt.style.color="red"; }else{
                txt.style.color="black";
                
            }

        }
    </script>
</body>
</html>